<template>
  <!-- 提醒设置组件 -->
  <div class="vy-cmp-cs-notice">
    <div class="vy-cmp-common-title">
      <span class="vy-cmp-common-title-left">提醒设置</span>
    </div>
    <div class="vy-cmp-cs-notice-container">
      <div class="vy-cmp-cs-notice-form">
        <a-form>
          <a-form-item label="未使用成员提醒" :colon="false" v-bind="formItemLayout"
            extra="未使用微信的成员收到聊天消息和应用消息，通过短信或邮件提醒他们 ">
            <a-checkbox :checked="!!formData.memberRemind" @change="click_change_checkbox('memberRemind', $event)">
              开启
            </a-checkbox>
          </a-form-item>
          <a-form-item label="打卡提醒" :colon="false" v-bind="formItemLayout"
            extra="未使用微信的成员收到聊天消息和应用消息，通过短信或邮件提醒他们  ">
            <a-checkbox :checked="!!formData.clockRemind" @change="click_change_checkbox('clockRemind', $event)">
              开启
            </a-checkbox>
          </a-form-item>
          <a-form-item label="作业提醒" :colon="false" v-bind="formItemLayout"
            extra="未使用微信的成员收到聊天消息和应用消息，通过短信或邮件提醒他们  ">
            <a-checkbox :checked="!!formData.workRemind" @change="click_change_checkbox('workRemind', $event)">
              开启
            </a-checkbox>
          </a-form-item>
          <a-form-item label="评论提醒" :colon="false" v-bind="formItemLayout"
            extra="未使用微信的成员收到聊天消息和应用消息，通过短信或邮件提醒他们  ">
            <a-checkbox :checked="!!formData.commentRemind" @change="click_change_checkbox('commentRemind', $event)">
              开启
            </a-checkbox>
          </a-form-item>
          <a-form-item label="讲师／领导点评提醒" :colon="false" v-bind="formItemLayout"
            extra="未使用微信的成员收到聊天消息和应用消息，通过短信或邮件提醒他们  ">
            <a-checkbox :checked="!!formData.lecturerRemind" @change="click_change_checkbox('lecturerRemind', $event)">
              开启
            </a-checkbox>
          </a-form-item>

          <a-form-item>
            <a-button type="primary" @click="click_save_info">保存更改</a-button>
          </a-form-item>
        </a-form>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: "vy-cmp-cs-notice",
  data() {
    return {
      formItemLayout: {
        labelCol: {
          span: 4
        },
        wrapperCol: {
          span: 20
        }
      },
      projectId: null, // 项目id
      // 表单字段数据
      formData: {
        memberRemind: 0, // 未使用成员提醒, 0: 未开启, 1: 已开启
        clockRemind: 0, // 打卡提醒, 0: 未开启, 1: 已开启
        workRemind: 0, // 作业提醒, 0: 未开启, 1: 已开启
        commentRemind: 0, // 评论提醒, 0: 未开启, 1: 已开启
        lecturerRemind: 0 // 讲师/领导点评提醒, 0: 未开启, 1: 已开启
      }
    };
  },
  created() {
    this.projectId = this.$route.query.projectId;
  },
  mounted() {
    this.$nextTick(() => {
      this.queryInfo();
    });
  },
  methods: {
    // 查询该项目提醒设置
    queryInfo() {
      let params = {
        projectId: this.projectId
      };
      this.$axios
        .get("/projectSetting/getRemindSetting", { params })
        .then(res => {
          this.formData.memberRemind = res.memberRemind;
          this.formData.clockRemind = res.clockRemind;
          this.formData.workRemind = res.workRemind;
          this.formData.commentRemind = res.commentRemind;
          this.formData.lecturerRemind = res.lecturerRemind;
        });
    },
    // 更新项目提醒设置
    saveInfo() {
      let params = Object.assign(
        {
          id: this.projectId
        },
        this.formData
      );
      this.$axios
        .post("/projectSetting/updateRemindSetting", params)
        .then(res => {
          if (res.success) {
            this.$message.success(res.msg);
          } else {
            this.$message.error(res.msg);
          }
        });
    },
    // checkbox change事件
    click_change_checkbox(field, e) {
      this.formData[field] = e.target.checked ? 1 : 0;
    },
    // 保存更改
    click_save_info() {
      this.saveInfo();
    }
  }
};
</script>

<style type="text/css" lang="scss">
.vy-cmp-cs-notice {
  width: 100%;
  height: 100%;
  background: #ffffff;
  .ant-form-item {
    border-bottom: 1px solid rgba(235, 235, 236, 1);
    padding: 12px 0;
    margin-bottom: 0;
    &:last-child {
      border: none;
    }
    .ant-form-item-label {
      text-align: left;
    }
  }
}
</style>
